package com.wy.thread;

import java.util.concurrent.*;

/**
 * @author 33117
 * @version 1.0
 * @data 2025/3/18 9:24
 * 多线程
 */
public class MyThread {
    public static ExecutorService executorService = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("------strat-------");
        // 继承Thread类
        new thread01().start();
        // Runable接口
        new Thread(new runable()).start();
        // callable接口
        FutureTask<Integer> futureTask = new FutureTask<>(new callable());
        new Thread(futureTask).start();
        Integer i = futureTask.get();
        System.out.println("结果集："+i);
        // 线程池
        executorService.execute(new thread01());
        System.out.println("------end-------");
    }

    public static class thread01 extends Thread {
        @Override
        public void run() {
            System.out.println("thread-当前线程：" + Thread.currentThread().getName());
        }
    }

    public static class runable implements Runnable {
        @Override
        public void run() {
            System.out.println("runable-当前线程：" + Thread.currentThread().getName());
        }
    }
    public static class callable implements Callable<Integer>{
        @Override
        public Integer call() throws Exception {
            System.out.println("callable-当前线程：" + Thread.currentThread().getName());
            return 123;
        }
    }
}
